package com.maxlen.order.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
@EnableConfigurationProperties(MyThreadPoolConfigProperties.class)
public class MyThreadPoolConfig {

    @Autowired
    private MyThreadPoolConfigProperties myThreadPoolConfigProperties;

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        return new ThreadPoolExecutor(
                myThreadPoolConfigProperties.getCorePoolSize(),
                myThreadPoolConfigProperties.getMaximumPoolSize(),
                myThreadPoolConfigProperties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(10000));
    }

}
